<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <title>欢迎页面-X-admin2.0</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <link rel="stylesheet" th:href="@{/css/font.css}">
    <link rel="stylesheet" th:href="@{/css/xadmin.css}">
    <script th:src="@{/webjars/jquery/3.5.1/jquery.min.js}"></script>
    <script th:src="@{/js/ions_alert.js}"></script>
    <script th:src="@{/common/common.js}"></script>
    <script th:src="@{/js/sweetalert.min.js}"></script>
    <link rel="stylesheet" th:href="@{/css/sweetalert.css}">
</head>

<body>
<div class="x-nav">
      <span class="layui-breadcrumb">
        <a href="#">首页</a>
        <a href="#">演示</a>
        <a>
          <cite>导航元素</cite></a>
      </span>
    <a class="layui-btn layui-btn-small" style="line-height:1.6em;margin-top:3px;float:right"
       href="javascript:location.replace(location.href);" title="刷新">
        <i class="layui-icon" style="line-height:30px">ဂ</i></a>
</div>
<div class="x-body">
    <div class="layui-row">
        <dd class="layui-form layui-col-md12 x-so">
            <input class="layui-input" placeholder="订单号" name="billNo" id="billNo">
            <input class="layui-input" placeholder="用户名" name="username" id="username">
            <input class="layui-input" placeholder="售货员名" name="salesName" id="salesName">
            <div class="layui-input-inline">
                <select name="pageSize" id="pageSize">
                    <option>--每页数据--</option>
                    <option>5</option>
                    <option>10</option>
                    <option>15</option>
                    <option>20</option>
                </select>
            </div>
            <button class="layui-btn" lay-submit="" lay-filter="search" id="search"><i class="layui-icon" >&#xe615;</i></button>
        </dd>
    </div>
    <table class="layui-table middle">
        <thead>
        <tr>
            <th>订单编号</th>
            <th>创建时间</th>
            <th>售货员名</th>
            <th>用户名</th>
            <th>商品详情</th>
            <th>总积分</th>
            <th>总金额</th>
        </tr>
        </thead>
        <tbody id="tbody" class="billList">
        </tbody>
    </table>
    <div class="page" id="page">
        <div>
            <a class="prev" href="javaScript:" id="begin" onclick="pageGo('begin')"><&lt;</a>
            <a class="prev" href="javaScript:" onclick="pageGo('forward')">&lt;</a>
            <button type="button" class="layui-btn layui-btn-fluid" id="currentPage">0</button>
            <a class="next" href="javaScript:" onclick="pageGo('nextPage')">&gt;</a>
            <a class="next" href="javaScript:" onclick="pageGo('end')">&gt;&gt;</a>
        </div>
    </div>
    <div>
        <span class="x-right" style="line-height:40px">共<span id="curr">1</span>页</span>&nbsp;&nbsp;&nbsp;
        <span class="x-right" style="line-height:40px">共<span id="many">1</span>条数据</span>&nbsp;&nbsp;&nbsp;

    </div>

</div>
<script>
    $(function () {

        $("#search").click(function () {
            let billNo = $("#billNo").val();
            let pageSize = $("#pageSize").val();
            let username = $("#username").val();
            let salesName = $("#salesName").val();

            //定义默认选项
            findBillPage(billNo,0,1,'search',pageSize,username,salesName);
        })
    });
    function pageGo(param){
        let billNo = $("#billNo").val();
        let currentPage = $("#currentPage").text();
        let curr = $("#curr").text();
        let pageSize = $("#pageSize").val();
        console.log(pageSize);
        let username = $("#username").val();
        let salesName = $("#salesName").val();
        findBillPage(billNo,currentPage,curr,param,pageSize,username,salesName);
    }
    //查找 订单页 通过订单编号 和当前页 最大页查找
    function findBillPage(billNo,currentPage,bigPage,param,pageSize,username,salesName) {
        $.ajax({
            url: "/admin/findBillPage",
            type: "PUT",
            data:　{
                billNo:billNo,
                param: param,
                currentPage: currentPage,
                bigPage:bigPage,
                username:username,
                pageSize:pageSize,
                salesName:salesName
            },
            success:function (resultInfo) {

                var text = '';

                for (let i = 0; i < resultInfo.data.list.length; i++) {
                    text += '<tr>\n' +
                        '                <td>'+resultInfo.data.list[i].billNo+'</td>\n' +
                        '                <td class="createTime">'+formatDate(resultInfo.data.list[i].createTime)+'</td>\n' +
                        '                <td class="createTime">' +
                        '                    <a style="color:#90dbdb;" href="#" onclick="x_admin_show(\'售货员详情\',\'/admin/bill/showSalesMessage?salesName='+resultInfo.data.list[i].salesName+'\',600,500)">'+resultInfo.data.list[i].salesName+'</a>\n' +
                        '                <td>\n' +
                        '                    <a style="color:#90dbdb;" href="#" onclick="x_admin_show(\'用户详情\',\'/admin/bill/showUserMessage?username='+resultInfo.data.list[i].userName+'\',600,500)">'+resultInfo.data.list[i].userName+'</a>\n' +
                        '                </td>\n' +
                        '                <td>\n' +
                        '                    <a style="color:#db6508;" href="#" onclick="x_admin_show(\'商品详情\',\'/admin/bill/showWaresMessage?billNo='+resultInfo.data.list[i].billNo+'\',600,500)">商品详情</a>\n' +
                        '                </td>\n' +
                        '                <td>'+resultInfo.data.list[i].points+'</td>\n' +
                        '                <td>'+resultInfo.data.list[i].allPrice+'</td>\n' +
                        '            </tr>';
                }
                text += '';
                $(".billList").html(text);
                $("#currentPage").html(resultInfo.data.currentPage);
                $("#many").html(resultInfo.data.totalCount);
                $("#curr").text(resultInfo.data.totalPage);

            }
        })
    }
    function formatDate(date) {
        var d = new Date(date),
            month = '' + (d.getMonth() + 1),
            day = '' + d.getDate(),
            year = '' + d.getFullYear(),
            hour = '' + d.getHours(),
            minutes = '' + d.getMinutes(),
            second = '' + d.getSeconds();

        if (month.length < 2) month = '0' + month;
        if (day.length < 2) day = '0' + day;
        if (hour.length < 2 ) hour = '0' + hour;
        if (minutes.length < 2 ) minutes = '0' + minutes;
        if (second.length < 2 ) second = '0' + second;

        return [year, month, day].join('-')+' '+[hour,minutes,second].join(':');
    }
</script>
</body>
</html>